package goods;

import com.alibaba.fastjson.JSON;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/shop")
public class ShopServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//        String[] str = req.getParameterValues("goods");
        String res = req.getParameter("goods");
        List<Goods> goods = JSON.parseArray(res, Goods.class);
        Cart cart = new Cart();
        cart.setGoodsList(goods);
        HttpSession session = req.getSession();
        session.setAttribute("cart",cart);
        resp.sendRedirect("goods.jsp");
    }
}